package com.fantasy.excel;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class WriteExcel {

	@SuppressWarnings("resource")
	public static void writeToExcel(List<ArrayList<String>> dataList , String path){
		System.out.println("writeToExcel:" + path);
		System.out.println("data size " + dataList.size());
		try {
			Workbook wb = new HSSFWorkbook();
			Sheet sheet = wb.createSheet();
			//int dataStartRowInx = Integer.valueOf(ReadProperties.read("Txt2excel.properties").getProperty("excelDataFormatRow")) -1;
			for(int i = 0 ; i < dataList.size(); i ++){
				Row row = sheet.createRow(i);
				ArrayList<String> elementList = dataList.get(i);
				for (int j = 0 ; j < elementList.size() ; j++) {
					Cell cell = row.createCell(j);
					cell.setCellValue(elementList.get(j));
				}
			}
			FileOutputStream fileOut = new FileOutputStream(path + "-result.xls");
			wb.write(fileOut);
			fileOut.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
